<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="../js/vue.js"></script>
<div id="app">
    <h2>计数器：{{counter}}</h2>
    <!--v-on: 指令用来绑定事件-->
    <button v-on:click="add">+</button>
    <button v-on:click="sub">-</button>
</div>

<script>

    const obj = {
        counter:0
    }
    const app = new Vue({
        el:'#app',
        data:obj,
        methods:{
            add:function (){
                this.counter++;
                console.log("add");
            },
            sub:function (){
                this.counter--;
                console.log("sub");
            }
        },

        //生命周期钩子函数 -----挂载时回调执行
        mounted:function (){
            console.log("mounted");
        },
        //生命周期钩子函数 -----创建时时回调执行
        created:function (){
            console.log("created")
        }
    })
</script>
</body>
</html>